{include file="public/header" title='后台首页' keywords='关键字'}
<script src="__JS__/pintuer.js"></script>
</head>
<body>
<div class="panel admin-panel">
    <div class="panel-head" id="add"><strong><span class="icon-pencil-square-o"></span>增加内容</strong></div>
    <div class="body-content">
        <form method="post" class="form-x" action="{:url('goodEdit',input('get.'))}" enctype="multipart/form-data">
            <input type="hidden" name="goods_id" value="{$list['goods_id']}">
            <div class="form-group">
                <div class="label">
                    <label>商品名：</label>
                </div>
                <div class="field">
                    <input type="text" class="input w50" value="{$list['goods_name']}" name="goods_name" data-validate="required:请输入商品名"/>
                    <div class="tips"></div>
                </div>
            </div>
            <div class="form-group">
                <div class="label">
                    <label>划线价格：</label>
                </div>
                <div class="field">
                    <input type="number" class="input w50" value="{$list['price']}" name="price" data-validate="required:请输入价格"/>
                    <div class="tips"></div>
                </div>
            </div>
            <div class="form-group">
                <div class="label">
                    <label>商城价格：</label>
                </div>
                <div class="field">
                    <input type="number" class="input w50" value="{$list['vip']}" name="vip" data-validate="required:请输入价格"/>
                    <div class="tips"></div>
                </div>
            </div>
            <div class="form-group">
                <div class="label">
                    <label>商品库存：</label>
                </div>
                <div class="field">
                    <input type="number" class="input w50" value="{$list['spec_qty']}" name="spec_qty" data-validate="required:请输入库存"/>
                    <div class="tips"></div>
                </div>
            </div>
            <div class="form-group">
                <div class="label">
                    <label>图片：</label>
                </div>
                <div class="field">
                    <input type="text" readonly id="url1" class="input tips" style="width:25%; float:left;" value="{$list['images']}" data-toggle="hover" data-place="right"/>
                    <input type="button" class="button bg-blue margin-left" value="+ 浏览上传">
                    <input type="file" name="image" onchange="url1.value=this.value" style="position:relative; z-index:1000px; filter:alpha(opacity=0);-moz-opacity:0; opacity:0; left:-155px;"/>
                </div>
            </div>
            <div class="form-group">
                <div class="label">
                    <label>轮播图：</label>
                </div>
                <div class="field">
                    <span id="img-list-box" style="margin-left: 25px;">
                        {foreach name="$list['default_image']" item="vo" empty=""}
                        <div style="position: relative;margin- right: 20px;margin-bottom: 15px;width: 132px;display: inline-block;border: 1px solid #CCC;background:#EEE;">
                        <span style="display: block;width: 120px;height: 80px;border: 1px solid #F2F1F0;margin: 5px;overflow: hidden;">
                        <img src="/static/{$vo}" style="width: 100%;height: 100%;" />
                        </span>
                        <input type="hidden" name="old_img[]" value="{$vo}" />
                        <a onclick="delImg(this);" style="z-index: 10;display: block;top: -8px;cursor:pointer;right: -8px;position:absolute;width: 20px;height: 20px;background: #CCC;border-radius:100%;text-align:center;line-height: 20px;border: 1px solid #C1C1C1;color: #555;">X</a>
                        </div>
                        {/foreach}
                    </span>
                    <span style="display:inline-block;height: 30px;position: relative;top:0px;left:0px;">
                        <a style="display: inline-block;width: 100px;height:30px;line-height: 30px;text-align:center;background: #F60;color: #FFF;">图片上传</a>
                        <input type="file" name="imgs[]" style="width: 100px;border: 1px solid red;position: absolute;top:0px;left: 0px;height: 30px;opacity: 0;" id="up-img-file" onchange="upimg(this)">
                        </span>
                </div>
            </div>
            <div class="form-group" id="typeTitle">
                <div class="label">
                    <label>分类标题：</label>
                </div>
                <div class="field">
                    <select name="cid" class="input w50">
                        <option value="">请选择分类</option>
                        {foreach $cate_one as $v}
                        <optgroup label="{$v['cate_name']}">
                            {if !empty($v['next'])}
                            {foreach $v['next'] as $vv}
                            <optgroup label="{$vv['cate_name']}">
                                {if !empty($v['next'])}
                                {foreach $vv['next'] as $vvv}
                                <option value="{$vvv['cate_id']}" {if $list['cate_id']==$vvv['cate_id']}selected{/if}>{$vvv['cate_name']}</option>
                                {/foreach}
                                {/if}
                            </optgroup>
                            {/foreach}
                            {/if}
                        </optgroup>
                        {/foreach}
                    </select>
                    <div class="tips"></div>
                </div>
            </div>
            <div class="form-group" id="brandTitle">
                <div class="label">
                    <label>品牌标题：</label>
                </div>
                <div class="field">
                    <select name="bid" style="padding:5px 15px; border:1px solid #ddd;">
                        <option value="">请选择品牌</option>
                        {foreach $brand_one as $k=>$v}
                        <option value="{$v['brand_id']}" {if $list['brand']==$v['brand_id']}selected{/if}>{$v['brand_name']}</option>
                        {/foreach}
                    </select>
                    <div class="tips"></div>
                </div>
            </div>
            <div class="form-group">
                <div class="label">
                    <label>其他属性：</label>
                </div>
                <div class="field" style="padding-top:8px;">
                    推荐
                    <input type="radio" name="recommended" value="1" {if $list['recommended']==1}checked{/if} id="" checked>
                    <input type="radio" name="recommended" value="0" {if $list['recommended']==0}checked{/if} id="">
                    下架
                    <input type="radio" name="if_show" value="1" {if $list['if_show']==1}checked{/if} id="" checked>
                    <input type="radio" name="if_show" value="0" {if $list['if_show']==0}checked{/if} id="">
                    热门
                    <input type="radio" name="recom" value="1" {if $list['recom']==1}checked{/if} id="" checked>
                    <input type="radio" name="recom" value="0" {if $list['recom']==0}checked{/if} id="">
                </div>
            </div>
            <div class="form-group">
                <div class="label">
                    <label>内容：</label>
                </div>
                <div class="field">
                    <textarea name="content" class="input" style="height:250px; border:1px solid #ddd;">{$list['description']}</textarea>
                    <div class="tips"></div>
                </div>
            </div>
            <div class="form-group">
                <div class="label">
                    <label></label>
                </div>
                <div class="field">
                    <button class="button bg-main icon-check-square-o" type="submit" name="edit" value="0">修改并返回</button>
                    <button class="button bg-main icon-check-square-o" type="submit" name="edit" value="1">修改并继续</button>
                </div>
            </div>
        </form>
    </div>
</div>
</body>
<script>
    function upimg(obj) {
        if (obj.value == "") {
            return;
        }
        var formdata = new FormData();
        //<input type="file" name="img" value="" />
        formdata.append("img", $(obj)[0].files[0]);//获取文件法二
        $.ajax({
            type: 'post',
            url: '{:url("Upload/ajaxUpload")}', //接口
            data: formdata,
            cache: false,
            processData: false, // 不处理发送的数据，因为data值是Formdata对象，不需要对数据做处理
            contentType: false, // 不设置Content-type请求头
            success: function (response) {
                console.log(response);
                var html = '<div style="position: relative;margin-right: 20px;margin-bottom: 15px;width: 132px;display: inline-block;border: 1px solid #CCC;background:#EEE;">'
                    + '<span style="display: block;width: 120px;height: 80px;border: 1px solid #F2F1F0;margin: 5px;overflow: hidden;">'
                    + '<img src="/static/' + response + '" style="width: 100%;height: 100%;" />'
                    + '</span>'
                    + '<input type="hidden" name="new_img[]" value="' + response + '" />'
                    + '<a onclick="delImg(this);" style="z-index: 10;display: block;top: -8px;cursor:pointer;right: -8px;position:absolute;width: 20px;height: 20px;background: #CCC;border-radius:100%;text-align:center;line-height: 20px;border: 1px solid #C1C1C1;color: #555;">X</a>'
                    + '</div>';
                $('#img-list-box').append(html);
            },
            error: function () {
            }
        });
    }

    function delImg(obj) {
        $(obj).parent('div').remove();
    }
</script>
</html>